package com.heima.common;


import com.heima.controller.R;
import com.heima.controller.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@Slf4j
//@ResponseBody  // 响应回去
//全局异常处理器
//@Component
//只处理标注一下注解的异常
//@RestControllerAdvice
@RestControllerAdvice(annotations = {RestController.class, Controller.class})
public class GlobalExpectionHander {

    //定义方法
    //该方法处理哪些异常
    @ExceptionHandler(BusinessException.class)
    public R handleBusionException(BusinessException e) {

        //记入日志
        log.warn(e.getMessage());
        //提示用户 错误信息
       return R.fail(e.getMessage());
    }

}
